package test05;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class t2_2 {
    public static void main(String[] args) throws Exception {

        //创建属性集对象
        Properties p=new Properties();

        //加载配置文件 Druid 连接池不能够主动加载配置文件 ,需要指定文件
        p.load(new FileInputStream("resources/druid.properties"));

        //通过工厂类获取连接池对象
        DataSource ds = DruidDataSourceFactory.createDataSource(p);
        Connection con = ds.getConnection();

        Statement statement = con.createStatement();

        String sql = "select * from employee";
        //执行查询操作,返回的是一个ResultSet结果对象
        ResultSet resultSet = statement.executeQuery(sql);
        //System.out.println(resultSet);

        while(resultSet.next()){
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String gender = resultSet.getString("gender");
            double salary = resultSet.getDouble("salary");
            double bonus = resultSet.getDouble("bonus");
            Date join_date = resultSet.getDate("join_date");
            System.out.println(id + "," + name + "," + gender + "," + salary + "," + bonus + "," + join_date);
        }
    }
}
